<template>
    <van-button
            :loading="isfollowloading"
            v-if="!getfollowuser"
            @click="changebtn"
            class="follow-btn"

            color="#3296fa"
            round
            size="small"
            icon="plus"
          >关注</van-button>
          <van-button
            :loading="isfollowloading"
            @click="changebtn"
            v-else
            class="follow-btn"
            round
            size="small"
          >已关注</van-button>
</template>

<script>
import { followuser, cancelfollow } from '@/api/article'
export default {
  data () {
    return {
      isfollowloading: false
    }
  },
  model: {
    prop: 'getfollowuser',
    event: 'changefollowuser'
  },

  props: {
    getfollowuser: {
      type: Boolean,
      required: true
    },
    art_id: {
      type: [Number, String, Object],
      required: true
    }
  },

  created () {

  },

  methods: {
    async changebtn () {
      this.isfollowloading = true
      try {
        if (this.getfollowuser) {
          await cancelfollow(this.art_id)
        } else {
          await followuser(this.art_id)
        }
        this.isfollowloading = false
        this.$emit('changefollowuser', !this.getfollowuser)
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
